import Mock from 'mockjs';
import operatorJson from '../../data/system/operator.json';

export default {
    className: "system.model.Operator",
    queryData: function(postData) {
        return Mock.mock({
            isSuccess: "Y",
            reason: "",
            message: [],
            "data": {
                "recordCount": 38,
                "pageCount": 1,
                "pageIndex": 1,
                "pageSize": 20,
                // "queryResult|38": [{
                //     "keyID|1000-9999": 1000,
                //     "operatorCode": /^[0-9][0-9][0-9][0-9][0-9]$/,
                //     "operatorName": Mock.mock('@ctitle'),
                //     "status": "有效",
                //     "lastUpdatedBy": "admin",
                //     "lastUpdateTime": Mock.mock('@now'),
                //     "version": 1,
                // }],
                "queryResult": operatorJson
            }
        });
    },
    queryByKeyID: function(postData) {
        var curFindObject = null;
        for (var i = 0; i < operatorJson.length; i++) {
            if (postData.keyID == operatorJson[i].keyID) {
                curFindObject = operatorJson[i];
                break;
            }
        }
        if (curFindObject == null) {
            return Mock.mock({
                isSuccess: "Y",
                reason: "",
                message: [],
                "data": {
                    "keyID|1000-9999": 2000,
                    "operatorCode": /^[0-9][0-9][0-9][0-9][0-9]$/,
                    "operatorName": Mock.mock('@ctitle'),
                    "status": "有效",
                    "lastUpdatedBy": "admin",
                    "lastUpdateTime": Mock.mock('@now'),
                    "version": 1,
                }
            });
        } else {
            return {
                isSuccess: "Y",
                reason: "",
                message: [],
                data: curFindObject,
            };
        }

    },
};